<?php

/**
 * sms.php
 *
 * Author: netman
 * DateTime:  2023/7/17 17:24
 */
class Listener_Order_Created_Sms extends Listener_Base
{
    public function handle($args)
    {
        $self       = new self();
        $self->args = $args;
        //判断队列是否开启,如果开启则把任务推送到队列
        if ($self->queue_status) {
            Queue::in('default', Listener_Order_Created_Sms::class, $args);
        } else {
            $self->perform();
        }
    }

    /**
     * 队列任务
     * @param $args
     * User: netman
     * Date: 2023/7/17 17:39
     */
    public function perform()
    {
        $order = $this->args;
        St_Log::write('短信通知', array('type' => $order['need_confirm']), 'event/order_created/log');
        switch ($order['need_confirm']) {
            case 2:
                $type = St_NoticeCommon::PRODUCT_ORDER_UNPROCESSING_MSGTAG;
                break;
            case 0:
            case 1:
            default:
                $type = St_NoticeCommon::PRODUCT_ORDER_PROCESSING_MSGTAG;
                break;
        }

        //用户通知信息
        $result = St_SMSService::send_product_order_msg($type, $order);
        St_Log::write('短信通知', array('type' => $type, 'ordersn' => $order['ordersn'], 'result' => $result), 'event/order_created/log');

        if ($order['typeid'] == 5) {
            $type   = St_NoticeCommon::PRODUCT_STOCK_EARLY_WARNING;
            $order  = Model_Spot::sms_handle($order);
            $result = St_SMSService::send_product_order_msg($type, $order);
            St_Log::write('短信通知', array('type' => $type, 'ordersn' => $order['ordersn'], 'result'  => $result), 'event/order_created/log');
        }
    }
}